<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Agp\CoreBundle\Manager;

use Agp\CoreBundle\Manager\BaseManager;

/**
 * Description of ContratoManager
 *
 * @author bondcs
 */
class ContratoManager extends BaseManager{
    
    public function persist($entity) {
        $cobrancas = $this->container->get('session')->get('cobrancas');
        foreach ($cobrancas as $cobranca){
            $cobranca->setContrato($entity);
            $this->container->get('agp.cobrancaContrato.manager')->gerarBoleto($cobranca);
            $entity->addCobrancasContrato($cobranca);
        }
        $this->container->get('session')->set('cobrancas', array());
        parent::persist($entity);
    }

    public function updateInversedBy($entity, $terminaisOriginais)
    {
        foreach ($terminaisOriginais->toArray() as $terminal){
                if (!in_array($terminal, $entity->getTerminais()->toArray())){
                    $terminal->setContrato(null);
                    $this->em->persist($terminal);
                    $this->em->flush();
                }
        }
        
        parent::update($entity);
    }
}

?>
